program HeapSort;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  arr: array of Integer;
  extr: array of Integer;
  i, n, m, k, l, num, aa, nm, nextr: Integer;

procedure SiftUp (num: Integer);
var
  temp: Integer;
begin
  while (0 = 0) do
  begin
    if (arr[num] < arr[(num-1) div 2]) and (num > 0) then
    begin
      temp:=arr[num];
      arr[num]:=arr[(num-1) div 2];
      arr[(num-1) div 2]:=temp;
      num:=(num-1) div 2;
    end else begin
      Break;
    end;
  end;
end;

procedure Heapify(num: Integer);
var
  a, b, k: Integer;
begin
  while (0 = 0) do
  begin
    a:=2000000000;
    b:=2000000000;
    if (2*num + 1 < nm) then
    begin
      a:=arr[2*num + 1];
    end;
    if (2*num + 2 < nm) then
    begin
      b:=arr[2*num + 2];
    end;
    if (a <= b) and (a < arr[num]) then
    begin
      k:=arr[num];
      arr[num]:=arr[2*num+1];
      arr[2*num+1]:=k;
      num:=2*num+1;
    end else if (b <= a) and (b < arr[num]) then
    begin
      k:=arr[num];
      arr[num]:=arr[2*num+2];
      arr[2*num+2]:=k;
      num:=2*num+2;
    end else begin
      Break;
    end;
  end;
end;

procedure Insert(l: Integer);
begin
  nm:=nm+1;
  SetLength (arr, nm);
  arr[nm-1]:=l;
  SiftUp(nm-1);
end;

procedure Extract;
var
  temp, max, j, nummax: Integer;
begin
  max:=-1;
  for j:=0 to nm-1 do
  begin
    if max < arr[j] then
    begin
      max:=arr[j];
      nummax:=j;
    end;
  end;
  temp:=arr[nummax];
  arr[nummax]:=arr[nm-1];
  arr[nm-1]:=temp;
  Heapify(nummax);
  SiftUp(nummax);
  nm:=nm-1;
  SetLength (arr, nm);
  SetLength (extr, nextr);
  extr[nextr-1]:=max;
  nextr:=nextr+1;
end;

begin
  nm:=1;
  nextr:=1;
  Readln(n);
  for i:=1 to n do
  begin
    if i > 1 then
    begin
      Read (aa);
      if aa = 0 then
      begin
        Read (l);
        Insert(l);
        Readln;
      end else begin
        Extract;
        Readln;
      end;
    end else begin
      Read (aa);
      Readln (aa);
      SetLength (arr, nm);
      arr[nm-1]:=aa;
    end;
  end;
  for i:=0 to nextr-2 do
  begin
    writeln(extr[i]);
  end;
end.
